package eclipse.util.maptools;
import java.awt.Color;
import java.awt.event.*;
import java.io.File;

import javax.swing.*;
import javax.media.opengl.jgloo.jgl2d.*;
import javax.media.opengl.jgloo.jglsh.*;

import eclipse.client.Database;
import eclipse.lib.map.*;
/**
 * The Menubar that is within the MapEditor window. 
 * This controls the MapEditor.
 */
/*
 * Copyright (c) 2009, TOD Productions All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
 *	- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 *	- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 *	-Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */
public final class MapEditorMenuBar extends JMenuBar implements ActionListener
{
	private static final long serialVersionUID = 582605972245249054L;
	/**
	 * Creates the MenuBar object
	 */
	public MapEditorMenuBar()
	{		
		menuAddLayer = new JMenuItem();
		menuWindow = new JMenu();
        menuFile = new JMenu();
        menuOpen = new JMenuItem();
        menuNew = new JMenuItem();
        menuSave = new JMenuItem();
        menuExit = new JMenuItem();
        menuEdit = new JMenu();
        menuWindowGeneralProperties = new JMenuItem();
        menuWindowLightingProperties = new JMenuItem();
        menuWindowLinkingProperties = new JMenuItem();
        menuWindowTileColorProperties = new JMenuItem();
        menuWindowTilesheet = new JMenuItem();
        menuWindowMapViewer = new JMenuItem();        
        menuEditFill = new JMenuItem();
        menuEditEyeDropper = new JMenuItem();
        menuView = new JMenu();
        menuViewMapGrid = new JCheckBoxMenuItem();
        menuViewLight = new JCheckBoxMenuItem();
        menuViewAttributes = new JCheckBoxMenuItem();
        menuAttribute = new JMenu();
        menuAttributeNone = new JMenuItem();
        menuAttributeBlock = new JMenuItem();
        menuAttributeNPCBlock = new JMenuItem();
        menuAttributeGuildBlock = new JMenuItem();
        menuAttributeItem = new JMenuItem();
        menuAttributeKey = new JMenuItem();
        menuAttributeKeyOpen = new JMenuItem();
        menuAttributeRoof = new JMenuItem();
        menuAttributeScripted = new JMenuItem();
        menuAttributeSign = new JMenuItem();
        menuAttributeArena = new JMenuItem();
        menuAttributeBank = new JMenuItem();
        menuAttributeHouse = new JMenuItem();
        menuAttributeClickable = new JMenuItem();
        menuLayer = new JMenu();        
        
        menuWindow.setText("Window");        
                
        menuWindowGeneralProperties.setText("General Properties");
        menuWindowGeneralProperties.addActionListener(this);        
        menuWindow.add(menuWindowGeneralProperties);
                
        menuWindowLightingProperties.setText("Lighting Properties");
        menuWindowLightingProperties.addActionListener(this);
        menuWindow.add(menuWindowLightingProperties);
        
        menuWindowLinkingProperties.setText("Linking Properties");
        menuWindowLinkingProperties.addActionListener(this);
        menuWindow.add(menuWindowLinkingProperties);
        
        menuWindowTileColorProperties.setText("Tile Color Editor");
        menuWindowTileColorProperties.addActionListener(this);
        menuWindow.add(menuWindowTileColorProperties);
        
        menuWindowTilesheet.setText("Tilesheet Palette");
        menuWindowTilesheet.addActionListener(this);
        menuWindow.add(menuWindowTilesheet);
        
        menuWindowMapViewer.setText("Map Display");
        menuWindowMapViewer.addActionListener(this);
        menuWindow.add(menuWindowMapViewer);
        
        menuFile.setText("File");

        menuAddLayer.setText("Add layer");
        menuAddLayer.addActionListener(this);        
        menuOpen.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        menuOpen.setText("Open");
        menuOpen.addActionListener(this);
        menuFile.add(menuOpen);     

        menuNew.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        menuNew.setText("New");
        menuNew.addActionListener(this);
        menuFile.add(menuNew);

        menuSave.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        menuSave.setText("Save");
        menuSave.addActionListener(this);
        menuFile.add(menuSave);
    
        menuExit.setText("Close");
        menuExit.addActionListener(this);
        menuFile.add(menuExit);

        this.add(menuFile);

        menuEdit.setText("Edit");        

        menuEditFill.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.CTRL_MASK));
        menuEditFill.setText("Fill");
        menuEditFill.addActionListener(this);
        menuEdit.add(menuEditFill);

        menuEditEyeDropper.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        menuEditEyeDropper.setText("Eye Dropper");
        menuEditEyeDropper.addActionListener(this);        
        menuEdit.add(menuEditEyeDropper);

        this.add(menuEdit);

        menuView.setText("View");

        menuViewMapGrid.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        menuViewMapGrid.setText("Map Grid");
        menuViewMapGrid.addActionListener(this);              
        menuView.add(menuViewMapGrid);

        menuViewLight.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        menuViewLight.setText("Day/Night");
        menuViewLight.addActionListener(this);
        menuView.add(menuViewLight);

        menuViewAttributes.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        menuViewAttributes.setText("Show Attributes");
        menuViewAttributes.addActionListener(this);
        menuView.add(menuViewAttributes);

        
        this.add(menuView);

        menuAttribute.setText("Attributes");

        menuAttributeNone.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeNone.setText("None");
        menuAttributeNone.addActionListener(this);
        menuAttribute.add(menuAttributeNone);

        menuAttributeBlock.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeBlock.setText("Block");
        menuAttributeBlock.addActionListener(this);
        menuAttribute.add(menuAttributeBlock);

        menuAttributeNPCBlock.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeNPCBlock.setText("NPC Block");
        menuAttributeNPCBlock.addActionListener(this);
        menuAttribute.add(menuAttributeNPCBlock);

        menuAttributeGuildBlock.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeGuildBlock.setText("Guild Block");
        menuAttributeGuildBlock.addActionListener(this);
        menuAttribute.add(menuAttributeGuildBlock);

        menuAttributeItem.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeItem.setText("Item");
        menuAttributeItem.addActionListener(this);
        menuAttribute.add(menuAttributeItem);

        menuAttributeKey.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeKey.setText("Key");
        menuAttributeKey.addActionListener(this);
        menuAttribute.add(menuAttributeKey);

        menuAttributeKeyOpen.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeKeyOpen.setText("Key Open");
        menuAttributeKeyOpen.addActionListener(this);
        menuAttribute.add(menuAttributeKeyOpen);

        menuAttributeRoof.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeRoof.setText("Roof");
        menuAttributeRoof.addActionListener(this);
        menuAttribute.add(menuAttributeRoof);

        menuAttributeScripted.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeScripted.setText("Scripted");
        menuAttributeScripted.addActionListener(this);
        menuAttribute.add(menuAttributeScripted);

        menuAttributeSign.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeSign.setText("Sign");
        menuAttributeSign.addActionListener(this);
        menuAttribute.add(menuAttributeSign);

        menuAttributeArena.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeArena.setText("Arena");
        menuAttributeArena.addActionListener(this);
        menuAttribute.add(menuAttributeArena);
        
        menuAttributeBank.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeBank.setText("Bank");
        menuAttributeBank.addActionListener(this);
        menuAttribute.add(menuAttributeBank);

        menuAttributeHouse.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeHouse.setText("House");
        menuAttributeHouse.addActionListener(this);
        menuAttribute.add(menuAttributeHouse);

        menuAttributeClickable.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.ALT_MASK));
        menuAttributeClickable.setText("Clickable");
        menuAttributeClickable.addActionListener(this);
        menuAttribute.add(menuAttributeClickable);

        this.add(menuAttribute);

        menuLayer.setText("Layer");        

        this.add(menuLayer);
        this.add(menuWindow);
	}
	private final void menuAddLayerActionPerformed(java.awt.event.ActionEvent evt)
	{
		final int layers = MapEditorApplication.map.getLayerCount();
		
		final Layer layerList[] = new Layer[layers + 1];
		
		for(int i = 0; i < layers; i++)
			layerList[i] = MapEditorApplication.map.getLayer(i);
		
		MapEditorApplication.map.setLayerCount(layers + 1);
		
		for(int i = 0; i < layers; i++)
			MapEditorApplication.map.setLayer(i, layerList[i]);
		
		this.addLayerButton(layers + 1);
		
		
	}
	private final void menuOpenActionPerformed(java.awt.event.ActionEvent evt)
	{
		final JFileChooser fc = new JFileChooser();
		final int ret = fc.showOpenDialog(null);
		if(ret == JFileChooser.APPROVE_OPTION)
		{									
			final File file = fc.getSelectedFile();
			MapEditorApplication.map = new MapFile().open(file.getAbsolutePath());
			
			final int layers 		= MapEditorApplication.map.getLayerCount();
			final int north 		= MapEditorApplication.map.getLinkedMaps().north;
			final int south 		= MapEditorApplication.map.getLinkedMaps().south;
			final int east 			= MapEditorApplication.map.getLinkedMaps().east;
			final int west 			= MapEditorApplication.map.getLinkedMaps().west;
			final int respawnMap 	= MapEditorApplication.map.getRespawn().map;
			final int respawnX 		= MapEditorApplication.map.getRespawn().x;
			final int respawnY 		= MapEditorApplication.map.getRespawn().y;
			final int respawnH 		= MapEditorApplication.map.getRespawn().height;
			final String mapName 	= MapEditorApplication.map.getName();
			final String mapMusic 	= MapEditorApplication.map.getMusic();
			final boolean lightEnabled = MapEditorApplication.map.isLightEnabled(0);
			final Color color 		= MapEditorApplication.map.getLightColor(0).toRGBColor();
			
			
			MapEditorApplication.generalProperties.txtMap.setText("" + respawnMap);
			MapEditorApplication.generalProperties.txtMapName.setText(mapName);		
			MapEditorApplication.generalProperties.txtMusic.setText(mapMusic);			
			MapEditorApplication.generalProperties.txtX.setText("" + respawnX);			
			MapEditorApplication.generalProperties.txtY.setText("" + respawnY);
			MapEditorApplication.generalProperties.txtZ.setText("" + respawnH);			
			
			MapEditorApplication.lightingProperties.chkEnabled.setSelected(lightEnabled);
			MapEditorApplication.lightingProperties.cmbLight.setSelectedIndex(0);

			MapEditorApplication.lightingProperties.colorChooser.setColor(color);
			
			MapEditorApplication.linkingProperties.txtNorth.setText("" + north);
			MapEditorApplication.linkingProperties.txtSouth.setText("" + south);
			MapEditorApplication.linkingProperties.txtEast.setText("" + east);
			MapEditorApplication.linkingProperties.txtWest.setText("" + west);
			addLayerButton(layers);
			
			
		}
	}
	private final void menuSaveActionPerformed(java.awt.event.ActionEvent evt)
	{
		final JFileChooser fc = new JFileChooser();
		final int ret = fc.showSaveDialog(null);
		if(ret == JFileChooser.APPROVE_OPTION)
		{
			final int north = Integer.parseInt(MapEditorApplication.linkingProperties.txtNorth.getText());
			final int south = Integer.parseInt(MapEditorApplication.linkingProperties.txtSouth.getText());
			final int east = Integer.parseInt(MapEditorApplication.linkingProperties.txtEast.getText());
			final int west = Integer.parseInt(MapEditorApplication.linkingProperties.txtWest.getText());
			
			MapEditorApplication.map.setLinkedMaps(north, south, east, west);
			
			final File file = fc.getSelectedFile();
			new MapFile(MapEditorApplication.map).save(file.getAbsolutePath());
		}
	}
	private final void menuViewLightActionPerformed(java.awt.event.ActionEvent evt)
	{
		System.out.println("enabling lights");
		MapEditorApplication.useLights = !MapEditorApplication.useLights;
	}
	private final void menuFileNewActionPerformed(java.awt.event.ActionEvent evt)
	{
		final int response = JOptionPane.showConfirmDialog(null, 
			"Openning a new map will remove all unsaved data on the currently openned map. \n" +
			"Do you wish to continue with opening a new map?"
		);
		if(response == JOptionPane.CANCEL_OPTION || response == JOptionPane.NO_OPTION)
			return;
		final int layers = Integer.parseInt(JOptionPane.showInputDialog("Number of layers: "));		
		MapEditorApplication.reset(layers);		
		addLayerButton(layers);
	}
	private final void menuWindowMapViewerActionPerformed(java.awt.event.ActionEvent evt)
	{
		MapEditorApplication.mapRenderer.setVisible(true);
	}
	private final void menuWindowTilesheetActionPerformed(java.awt.event.ActionEvent evt)
	{
		MapEditorApplication.tilePalette.setVisible(true);
	}
	private final void menuWindowLinkingPropertiesActionPerformed(java.awt.event.ActionEvent evt)
	{
		MapEditorApplication.linkingProperties.setVisible(true);
	}
	private final void menuWindowLightingPropertiesActionPerformed(java.awt.event.ActionEvent evt)
	{
		MapEditorApplication.lightingProperties.setVisible(true);
		MapEditorApplication.lightingProperties.chkEnabled.setEnabled(true);
	}
	private final void menuWindowGeneralPropertiesActionPerformed(java.awt.event.ActionEvent evt) 
    {
    	MapEditorApplication.generalProperties.setVisible(true);
    }
    private final void menuViewMapGridActionPerformed(java.awt.event.ActionEvent event)
    {
    	MapEditorApplication.mapRenderer.wireframe = !MapEditorApplication.mapRenderer.wireframe;
    }
    private final void menuEditFillActionPerformed(java.awt.event.ActionEvent event)
    {
    	if(MapEditorApplication.visLayer == null)
    	{
    		System.out.println("layer doesnt exist");
    		return;
    	}
    	final Layer layer = MapEditorApplication.visLayer;
    	final int width = layer.getWidth();
    	final int height= layer.getHeight();
    	
    	for(int x = 0; x < width; x++)
    	{
    		for(int y = 0; y < height; y++)
    		{
    			if(MapEditorApplication.drawAttr)
    			{
    				layer.setAttribute(x, y, TileAttribute.getAttribute((byte)MapEditorApplication.selAttribute));
    			}
    			else
    			{
    				final JGLTile tile = layer.getTile(x, y);
    				tile.setTexture(Database.tTileSheet[MapEditorApplication.selectSheet]);
    				tile.sheet = MapEditorApplication.selectSheet;
    				tile.setTile(MapEditorApplication.selectX / 32, MapEditorApplication.selectY / 32);
    				tile.setColor(new JGLColor(MapEditorApplication.tColor));
    			}
    		}
    	}
    }
    private final void menuEditEyeDropperActionPerformed(java.awt.event.ActionEvent event)
    {
    	//TODO: Unimplemented featuer: Eyedropper
    }   
    private final void menuLayerDisplayAll(ActionEvent event)
    {
    	MapEditorApplication.displayAll = !MapEditorApplication.displayAll;
    }
    private final void addLayerButton(int layers)
    {
    	menuLayer.removeAll();
    	menuLayer.add(menuAddLayer);
    	menuLayerLayer = new JMenuItem[layers + 1];
    	for(int i = 0; i < layers; i++)
    	{
    		menuLayerLayer[i] = new JMenuItem();
    		menuLayerLayer[i].setText("Layer" + i);
    		menuLayerLayer[i].addActionListener(new LayerButton(i));
    		menuLayer.add(menuLayerLayer[i]);    		
    	}
    	menuLayerLayer[layers] = new JMenuItem();
    	menuLayerLayer[layers].setText("Display All");
    	menuLayerLayer[layers].addActionListener(new ActionListener()    	
    	{
    		public final void actionPerformed(ActionEvent evt)
    		{
    			menuLayerDisplayAll(evt);
    		}
    	}
    	);
    	menuLayer.add(menuLayerLayer[layers]);
    }
    private final class LayerButton implements ActionListener
	{
    	private final int index;
    	public LayerButton(int index)
    	{
    		this.index = index;
    	}
		public final void actionPerformed(ActionEvent evt)
		{
			MapEditorApplication.visLayer = MapEditorApplication.map.getLayer(index);	
			System.out.println("Current layer: " + index);
		}
	}
	private final JMenu 				menuAttribute;
    private final JMenuItem	 			menuAttributeArena;
    private final JMenuItem 			menuAttributeBank;
    private final JMenuItem	 			menuAttributeBlock;
    private final JMenuItem 			menuAttributeClickable;
    private final JMenuItem 			menuAttributeGuildBlock;
    private final JMenuItem 			menuAttributeHouse;
    private final JMenuItem 			menuAttributeItem;
    private final JMenuItem 			menuAttributeKey;
    private final JMenuItem 			menuAttributeKeyOpen;
    private final JMenuItem 			menuAttributeNPCBlock;
    private final JMenuItem 			menuAttributeNone;
    private final JMenuItem 			menuAttributeRoof;
    private final JMenuItem 			menuAttributeScripted;
    private final JMenuItem 			menuAttributeSign;
    private final JMenu 				menuEdit;
    private final JMenuItem 			menuEditEyeDropper;
    private final JMenuItem 			menuEditFill;
    private final JMenuItem 			menuWindowGeneralProperties;
    private final JMenuItem				menuWindowLightingProperties;
    private final JMenuItem				menuWindowLinkingProperties;
    private final JMenuItem				menuWindowTileColorProperties;
    private final JMenuItem				menuWindowTilesheet;
    private final JMenuItem				menuWindowMapViewer;
    
    private final JMenuItem				menuAddLayer;
    private final JMenuItem 			menuExit;
    private final JMenu					menuWindow;
    private final JMenu 				menuFile;
    private final JMenu 				menuLayer;
    private 	  JMenuItem 			menuLayerLayer[];
    private final JMenuItem 			menuNew;
    private final JMenuItem 			menuOpen;
    private final JMenuItem 			menuSave;
    private final JMenu 				menuView;
    private final JCheckBoxMenuItem 	menuViewLight;
    private final JCheckBoxMenuItem 	menuViewMapGrid;
    private final JCheckBoxMenuItem 	menuViewAttributes;
	@Override
	public final void actionPerformed(ActionEvent e)
	{
		final Object src = e.getSource();
		if(src == menuWindowGeneralProperties)
			menuWindowGeneralPropertiesActionPerformed(e);
		else if(src == menuWindowTileColorProperties)
		{
			final Color c = JColorChooser.showDialog(null, "Tile Color Chooser", MapEditorApplication.tColor);		
			MapEditorApplication.tColor = c;
		}
		else if(src == menuWindowLightingProperties)
			menuWindowLightingPropertiesActionPerformed(e);
		else if(src == menuWindowLinkingProperties)
			menuWindowLinkingPropertiesActionPerformed(e);
		else if(src == menuWindowTilesheet)
			menuWindowTilesheetActionPerformed(e);
		else if(src == menuWindowMapViewer)
			menuWindowMapViewerActionPerformed(e);
		else if(src == menuAddLayer)
			menuAddLayerActionPerformed(e);
		else if(src == menuOpen)
			menuOpenActionPerformed(e);
		else if(src == menuNew)
			menuFileNewActionPerformed(e);
		else if(src == menuSave)
			menuSaveActionPerformed(e);
		else if(src == menuExit)
		{
			final int response = JOptionPane.showConfirmDialog(null, 
    			"Do you wish to exit? \n" +
    			"All unsaved data will be lost."
    		);
    		if(response == JOptionPane.NO_OPTION || response == JOptionPane.CANCEL_OPTION)
    			return;
    		System.exit(0);
		}
		else if(src == menuEditFill)
			menuEditFillActionPerformed(e);
		else if(src == menuEditEyeDropper)
			menuEditEyeDropperActionPerformed(e);
		else if(src == menuViewMapGrid)
			menuViewMapGridActionPerformed(e);
		else if(src == menuViewLight)
			menuViewLightActionPerformed(e);
		else if(src == menuViewAttributes)
			MapEditorApplication.drawAttr = !MapEditorApplication.drawAttr;
		else if(src == menuAttributeNone)
			MapEditorApplication.selAttribute = TileAttribute.NONE.getValue();
		else if(src == menuAttributeBlock)
			MapEditorApplication.selAttribute = TileAttribute.BLOCK.getValue();
		else if(src == menuAttributeNPCBlock)
			MapEditorApplication.selAttribute = TileAttribute.NPC_BLOCK.getValue();
		else if(src == menuAttributeGuildBlock)
			MapEditorApplication.selAttribute = TileAttribute.GUILD_BLOCK.getValue();
		else if(src == menuAttributeItem)
			MapEditorApplication.selAttribute = TileAttribute.ITEM.getValue();
		else if(src == menuAttributeKey)
			MapEditorApplication.selAttribute = TileAttribute.KEY.getValue();
		else if(src == menuAttributeKeyOpen)
			MapEditorApplication.selAttribute = TileAttribute.KEY_OPEN.getValue();
		else if(src == menuAttributeRoof)
			MapEditorApplication.selAttribute = TileAttribute.ROOF.getValue();
		else if(src == menuAttributeScripted)
			MapEditorApplication.selAttribute = TileAttribute.SCRIPTED.getValue();
		else if(src == menuAttributeSign)
			MapEditorApplication.selAttribute = TileAttribute.SIGN.getValue();
		else if(src == menuAttributeArena)
			MapEditorApplication.selAttribute = TileAttribute.ARENA.getValue();
		else if(src == menuAttributeBank)
			MapEditorApplication.selAttribute = TileAttribute.BANK.getValue();
		else if(src == menuAttributeHouse)
			MapEditorApplication.selAttribute = TileAttribute.HOUSE.getValue();
		else if(src == menuAttributeClickable)
			MapEditorApplication.selAttribute = TileAttribute.CLICKABLE.getValue();
	}
}
